<script setup>
import { provide } from 'vue';
import axios from 'axios';
import { useLoginedStore } from '@/stores/logined';
const store = useLoginedStore();
// console.log( store );
// 创建 axios 实例
const instance = axios.create({
  timeout: 1000
});
const fulfilled = config => {
  const token = store.token; // 通过 Store 的 Getter 获得 token
  if( token ) {
    // Authorization: <type> <credentials>
    // config.headers['Authorization'] = `Bearer ${token}`
    config.headers.set('Authorization', `Bearer ${token}`);
  }
  return config;
}
const rejected = error => Promise.reject(error);
instance.interceptors.request.use( fulfilled, rejected );
// 通过根组件向所有后代组件提供数据
provide('$http', instance)
</script>

<template>
  <router-view></router-view>
</template>

<style scoped>
</style>
